from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import render

# Create your views here.
from bookstore.models import UserInfo


def index(request):
    return HttpResponse('你好啊，欢迎来到地猫购书商城')


# 查询所有人员
def users(request):
    # 执行查询操作
    users = UserInfo.objects.all()
    return render(request, 'bookstore/users.html', context={'users': users, 'Title': '管理员列表'})


def create(request):
    # 1:创建对象
    user = UserInfo()
    user.username = '钱好多'
    user.password= '123456'
    user.phone = '12345678901'
    user.email = 'qhd@qq.com'
    user.save()
    return HttpResponse('操作成功')


def ajax_test(request):
    return render(request, 'bookstore/ajax_test.html')


def ajax_handle(request):
    return JsonResponse({'res':'你好啊！'})
